package com.oracle.sbdb.util;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class SimilarityUtils {
	public static double getSimilarity(List<String> list1, List<String> list2){
		double res = 0.0;
		
		if(list1 == null || list1.size() == 0 || list2 == null || list2.size() == 0){
			return res;
		}
		
		Set<String> intersaction = new HashSet<String>();
		Set<String> union = new HashSet<String>();
		
		union.addAll(list1);
		for(String word : list2){
			if(union.contains(word)){
				intersaction.add(word);
			}
			union.add(word);
		}
		
		res = (double)intersaction.size() / (double)union.size();
		
		return res;
	}
}
